<!--#include file="../../../easyasp/easp.asp" -->
<script language="JScript" runat="Server">
function ToObject(json) {
    var o;
    eval("o=" + json);
    return o;
}
function toArray(s){
    var dic = Server.CreateObject("Scripting.Dictionary")
    eval("var a=" + json);
    for(var i=0;i<a.length;i++){
        var obj = Server.CreateObject("Scripting.Dictionary")
        for(x in a[i]) obj.Add(x,a[i][x])
        dic.Add(i, obj);
    }
    return dic
}
</script>
<%
Function ret3(ret)
	if ret="1" then
		easp.echo "1"
	else
		easp.echo ret
	end if
End Function
easp.var("dy_zz_f")="zzmc,zzlb,isbn,zbdw,zb,js,cbsj"
easp.var("dy_zz_n")="著作名称,著作类别,ISBN,出版单位,主编,角色,出版时间"
easp.var("dy_hdry_f")="mc,dw,sj"
easp.var("dy_hdry_n")="荣誉名称,颁发单位,时间"
easp.var("dy_hybz_f")="mc,dw,sj"
easp.var("dy_hybz_n")="行标名称,颁发单位,时间"


easp.var("dy_zbhyjl_f")="mc,site,qzsj,cnt"
easp.var("dy_zbhyjl_n")="名称,地点,起止时间,参会人数"

easp.var("dy_cyhyjl_f")="mc,site,qzsj,cnt,nr"
easp.var("dy_cyhyjl_n")="名称,地点,起止时间,参会人数,报告题目内容"

easp.var("dy_gnwfw_f")="xm,qzsj,site,zzly"
easp.var("dy_gnwfw_n")="姓名,起止时间,访问国家城市单位,资助来源"

easp.var("dy_kpyz_f")="sj,site,mc"
easp.var("dy_kpyz_n")="时间,地点,名称"

easp.var("dy_xhrz_f")="xm,mc,zw,kssj"
easp.var("dy_xhrz_n")="姓名,学会名称,职务,开始担任时间"

easp.var("dy_cdjx_f")="sj,bj,kcmc,zc,kss,llsj"
easp.var("dy_cdjx_n")="时间,班级,课程名称,周次,课时数,理论实践"

Function pi(username)
	easp.var("username")=username
	dim ret,rs
	set rs=easp.db.sel("select pi from [pi] where [username]={username}")
	if rs.RecordCount>=1 then
		easp.var("pi")=rs("pi")
	end if
End Function

Function js4(fn,tn,title,zdy1,zdy1_title) 
	dim txt
	txt=myr(fn)
	txt=replace(txt,"[dy:tn]",tn)
	txt=replace(txt,"[dy:title]",title)
	txt=replace(txt,"[dy:zdy1]",zdy1)
	txt=replace(txt,"[dy:zdy1_title]",zdy1_title)
	js4=txt
	' Easp.Echo txt
End Function

Function js3(fn,field,title,width) 
	dim txt
	txt=myr(fn)
	txt=replace(txt,"[dy:field]",field)
	txt=replace(txt,"[dy:title]",title)
	if width<>"" then 
		txt=replace(txt,"100",width)
	end if
	js3=txt
	' Easp.Echo txt
End Function
Function js2(fn,fien,label,val) 
	dim txt
	txt=myr(fn)
	txt=replace(txt,"[dy:fieldn]",fien)
	txt=replace(txt,"[dy:label]",label)
	txt=replace(txt,"[dy:value]",val)
	js2=txt
	' Easp.Echo txt
End Function

Function js1(fn,tn,title) 
	dim txt
	txt=myr(fn)
	txt=replace(txt,"[dy:tn]",tn)
	txt=replace(txt,"[dy:title]",title)
	js1=txt
	' Easp.Echo txt
End Function
Function myr(filepath)
	filepath = "E:\w\epi_zu961i\web\dzps\src\" & "layuiadmin\tpl\lse\" & filepath
	myr = Easp.Fso.Read(filepath)
End Function

function retf(tnf)
	dim i,txt
	Set Rs = Easp.Db.Sel("select * from "&tnf)
	for i=0 to rs.fields.count-1
		if LCase(rs.fields(i).name)<>"id" then
			txt=txt & rs.fields(i).name & "," 
		end if
	next
	txt=left(txt,len(txt)-1)
	retf=txt
	response.write txt 
end function

Function idus(tn,fields,w,type1)
	dim sqla(10),ret,sql
	if type1=1 then
		easp.var(hr_1("lrr"))=session("username")
		sqla(0)=cr2(tn,fields & ",lrr")
		ret=execsw(sqla)
		ret1(ret)
	elseif type1=2 then
		ret=Easp.Db.Del(tn,w)
		ret1(ret)
	elseif type1=3 then
		sqla(0)=xg2(tn,fields,w)
		ret=execsw(sqla)
		ret1(ret)
	elseif type1=4 then
		if session("username")<>"admin" then
			w=w & " and lrr="& da(session("username"))
		else
		end if
		sql=Easp.Db.ToSql("select "&fields&" from "&tn & " where " & w)
		qry2json sql		
	end if
End Function

Function idus2(tn,fields,w,type1)
	dim sqla(10),ret,sql
	if type1=1 then
		sqla(0)=cr2(tn,fields)
		ret=execsw(sqla)
		ret1(ret)
	elseif type1=2 then
		ret=Easp.Db.Del(tn,w)
		ret1(ret)
	elseif type1=3 then
		sqla(0)=xg2(tn,fields,w)
		ret=execsw(sqla)
		ret1(ret)
	elseif type1=4 then
		sql=Easp.Db.ToSql("select "&fields&" from "&tn & " where " & w)
		qry2json sql		
	end if
End Function

Function ret2(ret)
	if ret=1 then
		retJson "0","成功",""
	else
		retJson "0","失败",""
	end if
End Function

Function ret1(ret)
	if ret=1 then
		easp.echo "1"
	else
		easp.echo "0"
	end if
End Function

Function qry2word(sql)
	dim rs,rsjson,json,s,i
	dim a,b
	set rs  = Easp.Db.GetRs(sql)
		for i=0 to rs.fields.count-1
			a=a&rs.Fields(i).name&","
		next
		a=left(a,len(a)-1) & "lselse"
	do while not rs.EOF
		for i=0 to rs.fields.count-1
			a=a&rs.Fields.Item(i)&","
		next	
		a=left(a,len(a)-1) 
		a=a & "lselse"
	rs.MoveNext   '指针移到下一行记录
	loop 
	a=left(a,len(a)-len("lselse"))
	Easp.Db.Close(rs)	
	qry2word=a
End Function

Function txt2file(txt)
	WriteToTextFile "D:\wwwroot\wlh_jh8tfd\web\src\" & "layuiadmin\tpl\lse\1\" & session("username") &"" & ".txt",txt,"UTF-8"
End Function


Function myr2 (FileUrl,CharSet)
	FileUrl="D:\wwwroot\wlh_jh8tfd\web\src\" & "layuiadmin\tpl\lse\1\" & FileUrl
	Easp.Echo FileUrl
	Easp.Echo ReadFromTextFile(FileUrl,"UTF-8")
End Function

Function ReadFromTextFile (FileUrl,CharSet)
	dim stm,str
	set stm=server.CreateObject("adodb.stream")
	stm.Type=2 '以本模式读取
	stm.mode=3
	stm.charset=CharSet
	stm.open
	stm.loadfromfile FileUrl
	str=stm.readtext
	stm.Close
	set stm=nothing
	ReadFromTextFile=str
End Function
Sub WriteToTextFile (FileUrl,byval Str,CharSet)
	dim stm
	set stm=server.CreateObject("adodb.stream")
		stm.Type=2 '以本模式读取
		stm.mode=3
		stm.charset=CharSet
		stm.open
		stm.WriteText str
		stm.SaveToFile FileUrl,2
		stm.flush
		stm.Close
	set stm=nothing
End Sub

Function qry2show(sql)
	dim rs,s,i
	easp.db.pagesize = easp.var("limit")
	set rs  = Easp.Db.GetRs(sql)
	for i=1 to rs.RecordCount
		easp.echo rs("regu1")&"<br>"
		rs.movenext
	next
End Function

Function qry2json(sql)
	dim rs,rsjson,json,s
	dim a,b
	easp.db.pagesize = easp.var("limit")
	set rs  = Easp.Db.GetRs(sql)
	Easp.Json.EncodeUnicode=false
	rsjson=Easp.Encode(rs)
	Easp.Db.Close(rs)
	set json=Easp.Decode(rsjson)
	json.put "total",easp.db.pagerecordcount

	s = json.toString()
	a =  instr(s,"[")
	b =  instr(s,"]")
	s = replace(s,"rows","data")
	s = replace(s,"total","count")
	
	Easp.Echo replace(s,"{",  "{" & syh("code") & ":0,"  & syh("msg") & ":" & syh("") & ",",1,1)
	set json = nothing
End Function
	
Function syh(txt)
	txt = chr(34)&txt&chr(34)
	syh=txt
End Function

Function da(txt)
	txt = chr(39)&txt&chr(39)
	da=txt
End Function

Function lbfh(txt)
	txt=da("%"&txt&"%")
	lbfh=" like " & txt
End Function

Function bfh(txt)
	txt=da("%"&txt&"%")
	bfh=txt
End Function

Function dkh(txt)
	txt="{"&txt&"}"
	dkh=txt
End Function

Function xkh(txt)
	txt="("&txt&")"
	xkh=txt
End Function

Function daj(txt)
	txt = "#" & txt& "#"
	daj=txt
End Function

Function xg(tn,field,w)
    dim fielda,s,i
	fielda=split(field,",")
	s="update " & tn &" set "
	for i=0 to ubound(fielda)
		fielda(i)=replace(fielda(i),"[","")
		fielda(i)=replace(fielda(i),"]","")
		s=s+fielda(i)+"="+dkh(fielda(i))+","
	next
	s=left(s,len(s)-1) 
	xg=s+" where "+w
End Function

Function xg2(tn,field,w)
    dim fielda,s,i
	fielda=split(field,",")
	s="update " & tn &" set "
	for i=0 to ubound(fielda)
		fielda(i)=replace(fielda(i),"[","")
		fielda(i)=replace(fielda(i),"]","")
		s=s+fielda(i)+"="+dkh(hr_1(fielda(i)))+","
	next
	s=left(s,len(s)-1) 
	xg2=s+" where "+w
End Function

Function cr2(tn,field)
    dim fielda,s,i
	fielda=split(field,",")
	s="insert into " & tn & xkh(field) & " values ("
	for i=0 to ubound(fielda)
		fielda(i)=replace(fielda(i),"[","")
		fielda(i)=replace(fielda(i),"]","")
		s=s+dkh(hr_1(fielda(i)))+","
	next
	s=left(s,len(s)-1) & ")"
	cr2=s
End Function
Function cr(tn,field)
    dim fielda,s,i
	fielda=split(field,",")
	s="insert into " & tn & xkh(field) & " values ("
	for i=0 to ubound(fielda)
		fielda(i)=replace(fielda(i),"[","")
		fielda(i)=replace(fielda(i),"]","")
		s=s+dkh(fielda(i))+","
	next
	s=left(s,len(s)-1) & ")"
	cr=s
End Function
Function hr_1(txt)
	hr_1="field[" & txt & "]"
End Function

Function getCheckData()
	dim result,ob,i,ids
	Set ob = toArray(json)
	For i=0 To ob.Count-1
	  ids=ids&ob(i)("ID") & "," 
	next
	easp.var("ids")=left(ids,len(ids)-1)
	Set ob = Nothing	
	result=easp.db.del("jf","id in ({ids})")
End Function
Function batchQrjf()
	dim result,ob,i,ids,ret
	Set ob = toArray(json)
	For i=0 To ob.Count-1
		' ids=ids&ob(i)("ID") & "," 
		easp.var("id")=ob(i)("ID")
		set rs=easp.db.sel("select qrjf from [jf] where id={id}")
		if rs("qrjf")=0 then
			ret=Easp.Db.Upd ("[jf]","qrjf=1","id={id}")    	
		end if
	next
	Set ob = Nothing
End Function

Function execsw(sqla)
	dim result,i
	easp.db.begin
	' sqla=split(sqls,";")
	for i=0 to ubound(sqla)
		if sqla(i)<>"" then
			result=easp.db.query(sqla(i))
			if not result then
				exit for
			end if
		end if
	next 
	if i<=ubound(sqla) then
		easp.db.RollBack
		execsw=0
	else
		easp.db.Commit
		execsw=1
	end if
End Function

Function retJson(code,msg,data)
		Easp.Echo "{" & syh("code") & ":"&code&","  & syh("msg") & ":" & syh(msg) & "," & syh("data") & ":{}"&"}"
End Function

Function clearSession()
	session("username")=""
	session("password")=""
End Function
%>